<template>
  <div class="home">
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ validator, message: '请填写正确的手机号' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field name="radio" label="单选框">
        <template #input>
          <van-radio-group v-model="radio" direction="horizontal">
            <van-radio name="01">用户</van-radio>
            <van-radio name="02">客服</van-radio>
          </van-radio-group>
        </template>
      </van-field>
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import myMixin from "../mixins/myMixin";
export default {
  name: "Home",
  mixins: [myMixin],
  data() {
    return {
      username: "",
      password: "",
      radio: "01",
    };
  },
  mounted() {},
  methods: {
    onSubmit(values) {
      let { username, radio } = values;
      let userInfo = {
        username,
        radio,
      };
      // 用radio当key值区分是谁登录了聊天室
      localStorage.setItem("userInfo", JSON.stringify(userInfo));
      this.$router.push({ path: "/about" });
    },
  },
};
</script>
